from pyecharts import options as opts
from pyecharts.charts import Boxplot


def data_manage(data: list):
    all_data_clear = []
    each_data_ = []
    for i in range(0, len(data)):
        each_data_ = list(data[i].split(','))
        each_data_clear = []
        for i in range(0, len(each_data_)):
            each_data_clear.append(int(each_data_[i]))
        all_data_clear.append(each_data_clear)
    return all_data_clear


def box_plot_sample(all_data):
    c = Boxplot(init_opts=opts.InitOpts(width="800px", height="500px"))  # 设置大小
    x_data = all_data.row_values(0)[1:]
    c.add_xaxis(x_data)
    for i in range(1, all_data.nrows):
        v = data_manage(all_data.row_values(i)[1:])
        c.add_yaxis(all_data.row_values(i)[0], c.prepare_data(v))
    c.set_global_opts(title_opts=opts.TitleOpts(title=all_data.name),
                      toolbox_opts=opts.ToolboxOpts(),
                      datazoom_opts=opts.DataZoomOpts(range_start=1, range_end=300)
                      )
    c.render()
